package com.enfi.business.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.enfi.business.domain.BusinessDevice;
import com.enfi.business.service.IBusinessDeviceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设备Controller
 * 
 * @author ruoyi
 * @date 2022-04-01
 */
@RestController
@RequestMapping("/device")
public class BusinessDeviceController extends BaseController
{
    @Autowired
    private IBusinessDeviceService businessDeviceService;

    /**
     * 查询设备列表
     */
    @RequiresPermissions("business:device:list")
    @GetMapping("/list")
    public TableDataInfo list(BusinessDevice businessDevice)
    {
        startPage();
        List<BusinessDevice> list = businessDeviceService.selectBusinessDeviceList(businessDevice);
        return getDataTable(list);
    }

    /**
     * 导出设备列表
     */
    @RequiresPermissions("business:device:export")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessDevice businessDevice)
    {
        List<BusinessDevice> list = businessDeviceService.selectBusinessDeviceList(businessDevice);
        ExcelUtil<BusinessDevice> util = new ExcelUtil<BusinessDevice>(BusinessDevice.class);
        util.exportExcel(response, list, "设备数据");
    }

    /**
     * 获取设备详细信息
     */
    @RequiresPermissions("business:device:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(businessDeviceService.selectBusinessDeviceById(id));
    }

    /**
     * 新增设备
     */
    @RequiresPermissions("business:device:add")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessDevice businessDevice)
    {
        return toAjax(businessDeviceService.insertBusinessDevice(businessDevice));
    }

    /**
     * 修改设备
     */
    @RequiresPermissions("business:device:edit")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessDevice businessDevice)
    {
        return toAjax(businessDeviceService.updateBusinessDevice(businessDevice));
    }

    /**
     * 删除设备
     */
    @RequiresPermissions("business:device:remove")
    @Log(title = "设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(businessDeviceService.deleteBusinessDeviceByIds(ids));
    }
}
